package test;


	public class testsyn extends Thread {  
	    private static String sync = "987";  
	    private String methodType = "";  
	          
	    public testsyn(String methodType) {  
	        this.methodType = methodType;  
	    }  
	  
	    private void method(String s){  
	    	synchronized(sync){  //哪怕是读取也会被锁住 
	    		//synchronized 表示在下列程序未进行完成期间, 该变量不得使用
               // sync=s;  
	    		System.out.println(this.methodType);
	            System.out.println(this.methodType+sync);  
	            while(true);  
	           }  
	    }  
	      
	    public void method1(){  
	        method("method1");  
	    }  
	      
	    public  void staticMethod1(){  
	        method("staticMethod1");  
	    }  
	      
	      
	    @Override  
	    public void run() {  
	        // TODO Auto-generated method stub  
	        if(methodType.equals("static"))  
	            staticMethod1();  
	        else  
	            method1();  
	    }  
	  
	    /** 
	     * @param args 
	     */  
	    public static void main(String[] args) {  
	        // TODO Auto-generated method stub  
	    	testsyn sample1 = new testsyn("nostatic");  
	    	testsyn sample2 = new testsyn("static");  
	        sample1.start();  
	        sample2.start();  
	    }  
	  
	}  

